﻿using AutoMapper;
using Pay.Core;
using Pay.Data;
using Pay.DTO;
using Pay.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Pay.Service.AutoMapper {
    
    public class MerchantReceivablesMapper : IStartupDto {
        private IMapperConfigurationExpression _cfg;
        public MerchantReceivablesMapper(IMapperConfigurationExpression cfg) {
            _cfg = cfg;
        }
        public void Execute() {
            Create();
        }
        protected virtual void Create() {
            _cfg.CreateMap<MerchantReceivables, merchant_receivables_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
                .ForMember(dest => dest.account_name, src => src.MapFrom(c => c.AccountName))
                .ForMember(dest => dest.card_no, src => src.MapFrom(c => c.CardNo))
                .ForMember(dest => dest.bank_name, src => src.MapFrom(c => c.BankName))
                .ForMember(dest => dest.branch_name, src => src.MapFrom(c => c.BranchName))
                .ForMember(dest => dest.region_id, src => src.MapFrom(c => c.RegionId))
                   .ForMember(dest => dest.region_name, src => src.MapFrom(c => c.RegionName))
                .ForMember(dest => dest.branch_address, src => src.MapFrom(c => c.BranchAddress))
                .ForMember(dest => dest.mobile, src => src.MapFrom(c => c.Mobile))
                .ForMember(dest => dest.wechat_qr_url, src => src.MapFrom(c => c.WechatQrUrl))
                .ForMember(dest => dest.ali_pay_account, src => src.MapFrom(c => c.AliPayAccount))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.update_time, src => src.MapFrom(c => c.UpdateTime.ToDateTime()));
            _cfg.CreateMap<MerchantReceivables, recivables_dto>()
               .ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
               .ForMember(dest => dest.account_name, src => src.MapFrom(c => c.AccountName))
               .ForMember(dest => dest.card_no, src => src.MapFrom(c => c.CardNo))
               .ForMember(dest => dest.bank_name, src => src.MapFrom(c => c.BankName))
               .ForMember(dest => dest.branch_name, src => src.MapFrom(c => c.BranchName))
               .ForMember(dest => dest.region_id, src => src.MapFrom(c => c.RegionId))
                  .ForMember(dest => dest.region_name, src => src.MapFrom(c => c.RegionName))
               .ForMember(dest => dest.branch_address, src => src.MapFrom(c => c.BranchAddress))
               .ForMember(dest => dest.mobile, src => src.MapFrom(c => c.Mobile))
               .ForMember(dest => dest.wechat_qr_url, src => src.MapFrom(c => c.WechatQrUrl))
               .ForMember(dest => dest.ali_pay_account, src => src.MapFrom(c => c.AliPayAccount));


            _cfg.CreateMap<merchant_receivables_dto, MerchantReceivables>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.MerchantId, src => src.MapFrom(c => c.merchant_id))
                .ForMember(dest => dest.AccountName, src => src.MapFrom(c => c.account_name))
                .ForMember(dest => dest.CardNo, src => src.MapFrom(c => c.card_no))
                .ForMember(dest => dest.BankName, src => src.MapFrom(c => c.bank_name))
                .ForMember(dest => dest.BranchName, src => src.MapFrom(c => c.branch_name))
                .ForMember(dest => dest.RegionId, src => src.MapFrom(c => c.region_id))
                 .ForMember(dest => dest.RegionName, src => src.MapFrom(c => c.region_name))
                .ForMember(dest => dest.BranchAddress, src => src.MapFrom(c => c.branch_address))
                .ForMember(dest => dest.Mobile, src => src.MapFrom(c => c.mobile))
                .ForMember(dest => dest.WechatQrUrl, src => src.MapFrom(c => c.wechat_qr_url))
                .ForMember(dest => dest.AliPayAccount, src => src.MapFrom(c => c.ali_pay_account))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.UpdateTime, src => src.MapFrom(c => c.update_time.ToUnix()));


        }
    }
}
